﻿using System;
using System.Collections.Generic;
using System.Text;
using DataLoad.iContact.WinClient.Properties;

namespace DataLoad.iContact.WinClient
{
    internal static class LoginManager
    {
        private static Encryptor _encryptor = new Encryptor(Encryptor.SymmProvEnum.DES);

        private static string _password;

        internal static string Password
        {
            get
            {
                return _password;
            }
            set
            {
                _password = value;
            }
        }

        private static string _username;

        internal static string Username
        {
            get
            {
                return _username;
            }
            set
            {
                _username = value;
            }
        }

        internal static string _captchaToken;

        public static string CaptchaToken
        {
            get
            {
                return _captchaToken;
            }
            set
            {
                _captchaToken = value;
            }
        }

        internal static string _captchaAnswer;

        public static string CaptchaAnswer 
        {
            get
            {
                return _captchaAnswer;
            }
            set
            {
                _captchaAnswer = value;
            }
        }

        internal static bool _captchaRequired = false;

        public static bool CaptchaRequired
        {
            get
            {
                return _captchaRequired;
            }
        }


        internal static void Load()
        {
            _rememberLogin = Settings.Default.RememberLogin;
            _username = Settings.Default.Username;
            string encryptedPassword = Settings.Default.Password;
            if (string.IsNullOrEmpty(encryptedPassword))
            {
                _password = string.Empty;
            }
            else
            {
                _password = _encryptor.Decrypting(Settings.Default.Password, Environment.UserName + "GoogleContacts");
            }
        }

        internal static void Save()
        {
            Settings.Default.Username = _username;
            Settings.Default.RememberLogin = _rememberLogin;
            if (_rememberLogin)
            {
                Settings.Default.Password = _encryptor.Encrypting(_password, Environment.UserName + "GoogleContacts");
            }
            else
            {
                Settings.Default.Password = string.Empty;
            }

            Settings.Default.Save();
        }

        private static bool _rememberLogin = false;

        internal static bool RememberLogin
        {
            get
            {
                return _rememberLogin;
            }

            set
            {
                _rememberLogin = value;
            }
        }
    }
}
